package com.web;

import com.bean.Menu;
import com.bean.Users;
import com.service.MenuService;
import com.service.UsersService;
import com.service.impl.MenuServiceImpl;
import com.service.impl.UsersServiceImpl;
import com.util.PageUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/power/menu/menus")
public class MenuServlet extends HttpServlet {
    private MenuService menuService = new MenuServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        if("select".equals(method)){
            select(req,resp);
        }
    }
    protected void select(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    //接收参数
    String index = req.getParameter("index");
    int pageIndex=(index==null||index.length()==0)?1:Integer.parseInt(index);
    //读取service方法(1.查询数据列表的方法 2.查询总条数的方法)
    PageUtil pageUtil = new PageUtil();
    List<Menu> menusList = menuService.getMenusList(pageIndex, pageUtil.getPageSize());
    int total = menuService.total();
        pageUtil.setTotal(total);
        pageUtil.setPageIndex(pageIndex);
        pageUtil.setDataList(menusList);

    //存值跳页面
        req.setAttribute("pi",pageUtil);
        req.getRequestDispatcher("list.jsp").forward(req,resp);
    }
}
